import api from './api';
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

export async function showStatus(dataLIST, label) {
  // label = {value: '需要修改的字段',type:'字典对应值机'}
  return new Promise((resolve, reject) => {
    const arr = {}

    api.getDictData({
      dictCode: label.type
    }).then(res => {
      arr[label.value] = res.data.map((item) => {
        return {
          name: item.dictName,
          value: item.dictValue
        }
      })
      dataLIST.forEach(mes => {
        for (let i in arr) {
          arr[i].forEach(m3 => {
            if (m3.value === mes[i]) {
              mes[i] = m3.name
            }
          })
        }
      })
      resolve(dataLIST)
    })
  });


}

export function getCode(code) {
  api.getDictData({
    dictCode: code
  }).then(res => {
    const arr = []
    arr = res.data.map((item) => {
      return {
        name: item.dictName,
        value: item.dictValue
      }
    })
  })
  return arr
}
export function isWithin24Hours(startDate, endDate) {
  const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
  const startTime = new Date(startDate).getTime()
  const endTime = new Date(endDate).getTime()
  const difference = endTime - startTime;
  return difference <= oneDay;
}
// module.exports = {
//   formatTime,
//   showStatus,
//   getCode
// }